package com.neusoft.cloudstreamfeign.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一返回结果类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    
    private Integer code;
    private String message;

    private String service;
    private T data;
    
    public static final Integer SUCCESS_CODE = 200;
    public static final Integer ERROR_CODE = 500;
    
    public Result(String service) {
        this.service = service;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(SUCCESS_CODE, "操作成功",null, data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(SUCCESS_CODE, message,null, data);
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(ERROR_CODE, message, null, null);
    }

    public boolean isSuccess() {
        return SUCCESS_CODE.equals(this.code);
    }

}
